/*
 * Entree: Heure Min Sec  Jour Mois An
 * Sortie: S M H J M A  en binaire inverse 
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char * words[] = { "sec: ", "min: ", "hou: ", "day: ", "mon: ", "yea: "};

void reverse_write_byte( int a, FILE * foutput){
	int i;
	for (i = 0; i < 8; i++){
		fputc('0'+a%2,foutput);
		a /= 2;
	}
	fputc('\n',foutput);
}


int main(int argn, char ** args){
    	int i;
	int t;
    	int date[6];
	time_t tim;
	struct tm osman;

	//get cur time
	if ( argn == 1){
		tim = time(NULL);

		osman = *(localtime(&tim));
		date[0] = osman.tm_hour;
		date[1] = osman.tm_min;
		date[2] = osman.tm_sec;
		date[3] = osman.tm_mday-1;
		date[4] = osman.tm_mon;
		date[5] = osman.tm_year -100;
		
	}else if ( argn == 7 ){
	    //from args
	    for (i = 0; i < 6; i++){
		    if ( sscanf(args[i+1], "%d", date + i) <= 0 ){
			    return -1;
		    }
		    if ( (i == 3) || (i == 4) ) {
			date[i] = date[i] - 1;
		    }
	    }
	}else return -1;

	//inverser H et S
	t = date[0];
	date[0] = date[2];
	date[2] = t;

	// reduire l'annee modulo 100
	date[5] = date[5] % 100;

	//affiche
	for (i = 0; i < 6; i++){
	    	printf("\t%s",words[i]);
		reverse_write_byte( date[i], stdout);
	}
	return 0;
}
